var baseUrl = "/api";

function checkLogin() {
    var username = getCookie("username");
    if(username==null||username===null||username==undefined||username===undefined) {
        window.location = '../../page/login.html'; // 跳转登录页面
    } else { // 校验cookie的username是否有效
        
    }
}

//创建cookie
function setCookie(cname, cvalue, minutes) {
    if(minutes==null||minutes===null||minutes==undefined||minutes===undefined||minutes<1) {
        document.cookie = cname + "=" + cvalue + "; " + "path=/; ";
    } else {
        var d = new Date();
        d.setTime(d.getTime()+(minutes*60*1000));
        var expires = "expires="+d.toGMTString();
        document.cookie = cname + "=" + cvalue + "; " + "path=/; " + expires;
    }
}

//删除cookie，把cookie的有效时间设置为过时时间就可以了
function deleteCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++)  {
        var c = ca[i].trim();
        if (c.indexOf(name)==0) {
            var d = new Date();
            d.setTime(d.getTime()-1000); //设置cookie时间为过期时间，让cookie失效
            var cvalue = c.substring(name.length,c.length);
            var expires = "expires="+d.toGMTString();
            document.cookie = cname + "=" + cvalue + "; " + "path=/; " + expires;
        }
    }
}

//获取cookie
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++)  {
        var c = ca[i].trim();
        if (c.indexOf(name)==0) {
            return c.substring(name.length,c.length);
        }
    }
    return null;
}

// login restful
var loginDataURL = baseUrl+"/management/instructor/login/";
// var loginDataURL = baseUrl+"/init.json";
var loginData = {"code":0,"data":"省级"}; // {"code":0, "data":"省级，市级，区级"};

// logout restful
var logoutDataURL = baseUrl+"/management/instructor/logout/";
// var logoutDataURL = baseUrl+"/init.json";
var logoutData = {"code":0,"data":"退出登录成功"};

// 根据审核状态分类
var verificationDataURL = baseUrl+"/management/instructor/verification/";
// var verificationDataURL = baseUrl+"/init.json";
var verificationData = {"code":0,"data":[{"ver_status":"已审核","count":2},{"ver_status":"未审核","count":1},{"ver_status":"待审核","count":1}]}

// 根据指导员等级分类
var classDataURL = baseUrl+"/management/instructor/class/";
// var classDataURL = baseUrl+"/init.json";
var classData = {"code":0,"data":[{"instructor_class":"国家级","count":1},{"instructor_class":"一级","count":1},{"instructor_class":"二级","count":1},{"instructor_class":"三级","count":1}]}

// 年检情况的数据
var inspectionDataURL = baseUrl+"/management/instructor/inspection/";
// var inspectionDataURL = baseUrl+"/init.json";
var inspectionData = {"code":0,"data":{"before":2,"after":2}}

// 男女比例的数据
var genderDataURL = baseUrl+"/management/instructor/gender/";
// var genderDataURL = baseUrl+"/init.json";
var genderData = {"code":0,"data":[{"sex":"male","count":2},{"sex":"femmale","count":1}]}

// 年龄比例
var ageDataURL = baseUrl+"/management/instructor/age/";
// var ageDataURL = baseUrl+"/init.json";
var ageData = {"code":0,"data":{"<20":10,"20-50":3,">50":1}}

// 运动项目比例饼状数据  篮球，足球，乒乓球，羽毛球
var typeDataURL = baseUrl+"/management/instructor/type/";
// var typeDataURL = baseUrl+"/init.json";
var typeData = {"code":0,"data":[{"instructor_type":"篮球","count":1},{"instructor_type":"足球","count":1},{"instructor_type":"羽毛球","count":1},{"instructor_type":"乒乓球","count":1}]}

// 根据地区分类的数据
var districtDataURL = baseUrl+"/management/instructor/district/";
// var districtDataURL = baseUrl+"/init.json";
var districtData = {"code":0,"data":[{"city":"太原市","count":1},{"city":"大同市","count":1},{"city":"杨泉市","count":1},{"city":"长治市","count":1}]}

// 获取所有用户
var allUserDataURL = baseUrl+"/management/instructor/users/all/";
// var allUserDataURL = baseUrl+"/init.json";
var allUserData = {"code":0,"data":[{"city":"太原市","count":1},{"city":"大同市","count":1},{"city":"杨泉市","count":1},{"city":"长治市","count":1}]}

// 获取用户所有管辖区域
var regionsDataURL = baseUrl+"/management/instructor/regions/";
// var regionsDataURL = baseUrl+"/init.json";
var regionsData = {"code":0,"data":{"太原市":["小店区","迎则区"],"大同市":["平城区"],"杨泉市":["矿区"],"长治市":["城区"]}}

// 用户数据URL
var usersDataURL = baseUrl+"/management/instructor/users/all/";
// var usersDataURL = "/test-api/users.json";
var usersDataData = {"code":0,"data":[{"id":1,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"1422012312wwww30213","tel":null,"edu_background":null,"is_instructor":"是","instructor_class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":2,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":3,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":4,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":5,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":6,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":7,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":8,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":9,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":10,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":11,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":12,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":13,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":14,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":15,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":16,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"},{"id":17,"name":"alan","sex":"male","age":23,"height":"168","weight":"64","address":null,"id_number":"142201231230213","tel":null,"edu":null,"is_ins":"是","class":"国家级","village":"小店区","city":"太原市","type":"篮球","ver_status":"已审核","province":"山西省","certi_num":"1212423","certi_date":"20200921","gym":null,"assessment":null,"upload_time":null,"annual_survey_date":"2020-01-04"}]}

// 用户新增URL
var userAddURL = baseUrl+"/management/instructor/users/add/";
// var userAddURL = "/test-api/users.json";
var userAddData = {"code":0,"data":null};

// 更新用户URL
var userUpdateURL = baseUrl+"/management/instructor/users/update/";
// var userUpdateURL = "/test-api/users.json";
var userUpdateData = {"code":0,"data":null};

// 删除用户URL
var userDeleteURL = baseUrl+"/management/instructor/users/delete/";
// var userDeleteURL = "/test-api/users.json";
var userDeleteData = {"code":0,"data":null};

// 评论列表
var commentDataURL = baseUrl+"/management/instructor/moment/";

// 反馈列表
var feedBackDataURL = baseUrl+"/management/instructor/feedback/";


function responseSuccess(miniAdmin, data) {
    if(data == null || data.code == null) {
        miniAdmin.error('服务内部错误');
        return "error";
    } else if (data.code!=0) {
        if("未登录"===data.data) {
            window.location = '../../page/login.html';
        } else {
            miniAdmin.error(data.data);
            return "error";
        }
    }
    return "success";
}

function isNotDistrictAccess(access) {
    if(access!=null && access!=undefined && (access=='省级' || access=='市级')) {
        return "yes";
    } else {
        return "no";
    }
}